﻿<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Admin.Master" Inherits="System.Web.Mvc.ViewPage<MvcEngineModelItem<MvcEngine.HtmlText.Models.Entities.HtmlTextItem>>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="Head" runat="server">
    <title><%= Model.Localize("EditTextPageTitle")%></title>
    <% Html.RenderCssFile("HtmlText.css"); %>
</asp:Content>


<asp:Content ID="indexContent" ContentPlaceHolderID="MainContent" runat="server">
    <%= Html.SuccessNotification("successNotification", Model.Localize("TextSaveSuccessNotification"))%>
    <%= Html.ErrorNotification("errorNotification", Model.Localize("TextSaveErrorNotification"))%>
    <div class="page-title" id="text-header">
         <h1><%= this.Model.Localize("EditTextPageHeader")%></h1>
    </div>
    
    <div class="page-menu">
        <%= Html.UrlActionLink(Model.Localize("BackLink"), Url.HtmlTexts())%>&nbsp;|&nbsp;
        <%= Html.UrlActionLink(Model.Localize("SaveLink"), "javascript:void(0);", new { onclick = "Save();" })%>
    </div>
    
<% using (Html.BeginForm(Url.SaveText(Model.Item.PageContentId), new { enctype = "multipart/form-data", id = "editHtmlTextForm" }))
   {%>
<% Html.RenderEditor("CKEditor", "Content", Model.Item.Text); %>
<div class="submitShortForm">
    <div class="form-field">
        <label for="Post_Slug">
            <%=Model.Localize("UploadFileLabel")%></label>
        <div class="form-element">
            <input type="file" id="file" name="file" />
            <%= Html.SubmitButton(Model.Localize("UploadButton"), "editHtmlTextForm", Url.UploadFile(Model.Item.PageContentId), new { @class = "submit-button" })%>
        </div>            
    </div>
</div>
<%= Html.MvcEngineAntiForgeryToken(m => m.AntiForgeryToken) %>
<%} %>
    	<script type="text/javascript">

    	    function Save() {
    	        var options = {
    	            success: function(data) {
    	                var json = JSON.parse(data);

    	                $('.notification').hide('slow');
    	                if (json.model != "valid") {
    	                    var result = "<ul>";
    	                    for (var i in json.errors) {
    	                        result += "<li>" + json.errors[i] + "</li>";
    	                    }
    	                    result += "</ul>";
    	                    $('#errorNotification').show('fast');
    	                    $('#errorNotification .notification-msg-content').html(result);
    	                }
    	                else {
    	                    $('#successNotification').show('fast');
    	                }
       	            },
    	            error: function (request, textStatus, errorThrown) {
    	                $('.notification').hide('fast');
    	                $('#errorNotification').show('fast');
    	            }
    	        };

    	        $('#editHtmlTextForm').ajaxSubmit(options);
    	    }
    
    </script>
</asp:Content>
